<?php
$this->widget('webroot.admin.protected.extensions.fancybox.EFancyBox', array('target' => '.cart', 'config' => array('width' => 520, 'height' => 180,'type'=>'iframe','hideOnOverlayClick'=>false,'onClosed'=>'js:function(){window.location.href="'.Yii::app()->createUrl("shop/cart").'";}')));
?>
<style type="text/css">
#apDiv1 {
	position:relative;
	left:520px;
	top:-60px;
	width:263px;
	height:48px;
	z-index:1;
}
#apDiv2 {
	position:absolute;
	left:458px;
	top:192px;
	width:210px;
	height:32px;
	z-index:1;
}
</style>
<script>
function check(){
	var cartCoin = <?=(int)Yii::app()->shoppingCart->getDiscountCoin()?>;
	var userCoin = <?=(int)$user->coin?>;
	var coin = document.getElementById('coin');
	var r = /^\d+$/　　//正整数    

	if(!(coin == null)){
		if(!r.test(coin.value)){
			alert('請輸入數字！');
			coin.focus();
			return false;
		}
		if(coin.value>userCoin){
			alert('輸入值大於您的餘額，請重新輸入！');
			coin.focus();
			return false;
		}
		if(coin.value>cartCoin){
			alert('輸入值大於當前購物金使用上限，請重新輸入！');
			coin.focus();
			return false;
		}
	}
	
	
	document.form1.submit();
}
</script>
<div id="contener" _height="auto">
	<div class="left_menu">
		<?php $this->beginWidget('application.widget.site.classWidget'); ?>
		<?php $this->endWidget(); ?>
		<?php $this->beginWidget('application.widget.site.productWidget'); ?>
		<?php $this->endWidget(); ?>
	</div>
	<div class="main">
		<?php $this->beginWidget('application.widget.site.newWidget'); ?>
		<?php $this->endWidget(); ?>
		<div class="right_mainBox">
			<div class="right_mainBox_top"></div>
			<div class="mainContentBox">
				<div class="mainMenu"> <img src="images/buySTEP.png" width="724" height="75" class="buySTEP" />
					<form action="<?=Yii::app()->createUrl('shop/CoinDiscount')?>" method="post" name="form1" id="form1">
					<div class="memberBOX3">
						<h4>親愛的 <span class="name"><?=Yii::app()->user->name?></span> 會員您好: </h4>
						<?php
						if(!Yii::app()->shoppingCart->isEmpty()){
						?>
						<table width="720" border="0" align="center" cellpadding="0" cellspacing="3">
							<tr>
								<th scope="col" width="400">商品名稱</th>
								<th scope="col">優惠價</th>
								<th>數量</th>
								<th scope="col">小計</th>
								<th scope="col" width="70">刪除</th>
							</tr>
							<?php
							if($rowset){
								foreach($rowset as $row){
							?>
							<tr>
								<td><a href="<?=Yii::app()->createUrl('shop/detail',array('pid'=>$row->pid))?>" class="green">&#8226;&nbsp;<?=$row->pname?></a></td>
								<td>$<?=$row->getPrice()?></td>
								<td><?=$row->getQuantity()?></td>
								<td>$<?=$row->getSumPrice()?></td>
								<td><input type="button" onclick="self.location.href='<?=Yii::app()->createUrl('shop/remove',array('pid'=>$row->pid))?>'" value="刪除" name=""></td>
							</tr>
							<?php
								}
							}
							?>							
							<?php
							if(Yii::app()->shoppingCart->getDiscountCoin()>=Yii::app()->params['minDiscountCoin']){
							?>
							<tr>
								<td class="green" colspan="5">你目前的購物金有&nbsp;$<?=(int)$user->coin?>&nbsp;可扣抵金額&nbsp;&nbsp;$<?=Yii::app()->shoppingCart->getDiscountCoin()?>&nbsp;&nbsp;輸入你要扣抵的購物金&nbsp;<input type="text" size="5" name="coin" id="coin" value="<?=(int)Yii::app()->session->get('coin')?>"></td>
							</tr>
							<?php
							}
							?>
						</table>
						<div id="apDiv11">訂單金額總計 <span class="red">NT$<?=Yii::app()->shoppingCart->getCost()-Yii::app()->session->get('coin')?></span>元</div>
						<div id="apDiv1">
							<input type="button" name="button" id="button" value="繼續選購本店商品" onclick="self.location.href='<?=Yii::app()->createUrl('shop/index')?>'"/>
							<input type="button" onclick="check();" name="button2" id="button2" value="我要結帳" />
						</div>
						<?php
						}else{
						?>
							<h4>購物清單中沒有商品。&nbsp;&nbsp;<input type="button" onclick="self.location.href='<?=Yii::app()->createUrl('shop/index')?>'" value="繼續選購本店商品" id="button" name="button"> </h4>
						<?
						}
						?>
					</div>
					</form>
				</div>
			</div>
			<div class="right_mainBox_bottom"></div>
		</div>
	</div>
</div>
